<form class="layui-form " action="" lay-filter="dataForm">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sort"  placeholder="请输入数字" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <img src="{$pic ?: ''}" alt="" class="uploadImg">
            <input type="hidden" name="pic" value="{$pic}">
            <button type="button" class="layui-btn upload pic">
                <i class="layui-icon">&#xe67c;</i>上传图标
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="dataSubmit">确定</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'http', 'laydate','upload'], function () {
        var form = layui.form;
        var http = layui.http;
        var $ = layui.$;

        var upload = layui.upload;
        upload.render({
            elem: '.upload',
            url: '/product/uploadpic/',
            before: function (obj) {
                layer.load()
            },
            done: function (res, index, upload) {
                layer.closeAll('loading')
                if (res.code == 0) {
                    var item = this.item;
                    $(item[0]).parent().find(".uploadImg").attr('src',
                        res.data)
                    $(item[0]).parent().find("input[name=pic]").val(res
                        .data)
                } else {
                    layer.msg(res.message)
                }
            },
            error: function (index, upload) {
                layer.closeAll('loading')
                layer.msg('上传接口出错')
            }
        });
        //表单初始赋值
        form.val('dataForm', {
            "id": "{$id}",
            "name": "{$name}",
            "sort": "{$sort}",
        })
        //监听提交
        form.on('submit(dataSubmit)', function (data) {
            http.post('/product/productBrandEdit', data.field, function (res) {
                if (res.code == 0) {
                    parent.layui.table.reload('dataTable');
                    parent.layer.closeAll('page');
                }
            }, $(this))
            return false;
        })
    })
</script>